<%@ page import="com.yft.dao.base.BaseConstant" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/include/taglibs.jsp" %>
<%
	if(session.getAttribute(BaseConstant.SESSION_MEMBER)!= null){
		response.sendRedirect(request.getContextPath()+"/yft/yftCrmLogin/getMain.html");
	}
%>
<!DOCTYPE HTML>
<html>
<head>
<title>客户关系管理平台 - 用户登录</title>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<%@ include file="/include/ext.jsp"%>
<link href="${basePath}/login/style/login.css" type="text/css" rel="stylesheet"/>
<link href="${basePath}/login/style/box.css" type="text/css" rel="stylesheet"/>
<META content="MSHTML 6.00.2900.3354" name=GENERATOR>
<script type="text/javascript">
	function initMsg(){
		document.getElementById("logErrorMsg").innerHTML = '';
	} 
	function showCode(){
		Ext.Ajax.request({
			url : '${basePath}/auth/createValidateCode.do',
			callback:function(options,success,response){
				var m =Ext.decode(response.responseText);
				if(m.success){
					document.getElementById('codeRealValue').value = m.msg;
					document.getElementById("codeId").src = "${basePath}/auth/getValidateCode.html?code="+(new Date().getTime().toString(36));
				}
			}
		});	
	}
	function validateData(){
		var flag = false;
		var str = "*&nbsp;";
		
		var obj = document.getElementById("logErrorMsg");
		obj.innerHTML = "";
		
		var loginID = document.getElementById('loginID').value;
		var password = document.getElementById('password').value;
		var codeValue = document.getElementById('codeValue').value;
		if(loginID == ''){
			document.getElementById('loginID').focus();
			obj.innerHTML = str + "对不起,请输入用户名!";
		}
		else if(password == ''){
			document.getElementById('password').focus();
			obj.innerHTML = str + "对不起,请输入密码!";
		}
		else if(codeValue == ''){
			document.getElementById('codeValue').focus();
			obj.innerHTML = str + "对不起,请输入验证码!";
		}else if(document.getElementById('codeValue').value.toLowerCase() != document.getElementById('codeRealValue').value.toLowerCase()){
			document.getElementById('codeValue').focus();
			obj.innerHTML = str + "对不起,验证码错误,请重新输入!";
			showCode();
			document.getElementById('codeValue').value = '';
		}else{
			document.getElementById('waitImg').style.display = "inline";
			document.getElementById('loginButton').disabled = true;
			document.getElementById('loginButton').innerHTML='请稍候...';
			document.getElementById('loginID').disabled = true;
			document.getElementById('password').disabled = true;
			document.getElementById('codeValue').disabled = true;
			document.getElementById('formResetButton').disabled = true;
			Ext.Ajax.request({
				url : '${basePath}/auth/processLogin.html',
				params:{loginID:loginID,password:password,codeValue:codeValue},
				callback:function(options,success,response){
					var m =Ext.decode(response.responseText);
					if(m.success){
						window.location.href ='${basePath}/yft/yftCrmLogin/getMain.html';
					}else{
						obj.innerHTML = str + m.error;
						document.getElementById('loginID').select();
						document.getElementById('password').value ='';
						document.getElementById('codeValue').value ='';
						showCode();
						document.getElementById('waitImg').style.display = "none";
						document.getElementById('loginButton').innerHTML='登 录';
						document.getElementById('loginButton').disabled = false;
						document.getElementById('loginID').disabled = false;
						document.getElementById('password').disabled = false;
						document.getElementById('codeValue').disabled = false;
						document.getElementById('formResetButton').disabled = false;
					}
				}
			});	
		}
	};
	
	function keyEnter(e){
		e = e || window.event;
		if(e.keyCode ==13){
			validateData();
		}
	}
	
</script>
</head>
<body onload="showCode();document.getElementById('loginID').focus();">
<form id="login_form" action="" method="post">
	<div class="login" onkeydown="keyEnter(event);">
    	<ul>
        	<li class="login-left"><img src="${basePath}/login/images/sys_03.jpg" width="35" height="342"></li>
            <li class="login-center">
            	<ol>
                	<li class="system">
                    	<img src="${basePath}/login/images/sys_13.jpg"  width="531" height="84">
                    </li>
                    <li class="li-em">
                    	<em><span id="logErrorMsg" style="color: red"></span></em>
                    </li>
                    <li class="li-text li-input">
                    	<span>用户名：</span><input type="text" maxLength=30 name=loginID id=loginID onkeydown="initMsg();"/>
                    </li>
                    <li class="li-input">
                    	<span>密　码：</span><input type="password" maxLength=32 name=password id=password onkeydown="initMsg();"/>
                    </li>
                    <li class="li-input li-validation">
                 	   	<input type="hidden" id="codeRealValue" name="codeRealValue" />
                    	<span>验证码：</span><input type="text" style="width:100px;" maxLength=4 name="codeValue" id="codeValue" onkeydown="initMsg();"/><img id="codeId" src="" width="78" height="26"><a href="javascript:showCode();">看不清？换一张</a>
                    </li>
                    <li class="li-button">
                    	<div><img id="waitImg" src="${basePath}/login/images/wait.gif" style="display: none"></div>
						<button id="loginButton" onclick="validateData();" type="button">登 录</button>
                        <button id="formResetButton" onclick="document.getElementById('login_form').reset();document.getElementById('logErrorMsg').innerHTML = '';document.getElementById('loginID').focus();" type="button">清 除</button>
                    </li>
                    <li class="li-img">
                    	<img src="${basePath}/login/images/crm.jpg" width="177" height="42">
                    </li>
                </ol>
            </li>
            <li class="login-right"><img src="${basePath}/login/images/sys_07.jpg" width="35" height="342"></li>
        </ul>
    </div>
</form>
</body>
</html>
